package ch.zbw.pra.sysventory.presentation.panels;

import java.util.List;

import ch.zbw.pra.sysventory.application.controller.SoftwareController;
import ch.zbw.pra.sysventory.model.Software;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

/**
 * Painted das SoftwareArchivePanel
 * 
 * @author Ralph Koster
 */

public class SoftwaresArchivePanel extends VerticalLayout {

	private static final long serialVersionUID = 1L;
	private SoftwareController softwareController;
	private Table softwareTable;
	
	public SoftwaresArchivePanel(){
		this.softwareTable = new Table ("Software im Netzwerk:");
		this.softwareController = new SoftwareController();
		paint();
		loadSoftwares();
	}

	private void paint() {
		this.setCaption("Software");
		this.setStyleName("softwareArchivePanel");
		softwareTable.setStyleName("table");
		softwareTable.addContainerProperty("Software Name", String.class, null);
		softwareTable.addContainerProperty("Software Version", String.class, null);
		softwareTable.addContainerProperty("Software Hersteller", String.class, null);
		this.addComponent(softwareTable);
		this.setComponentAlignment(softwareTable, Alignment.MIDDLE_CENTER);
	}

	private void loadSoftwares() {
		softwareTable.removeAllItems();
		List<Software> softwares = softwareController.loadSoftwares();
		for(Software software : softwares) {
			int softwareId = software.getSoftwareId();
			String softwareName= software.getNameSoftware();
			String softwareVendor = software.getSoftwareVendor();
			String softwareVersion = software.getVersionSoftware();
			softwareTable.addItem(new Object[] {
				    softwareName,softwareVersion,softwareVendor},softwareId);
		}		
	}

	public void updateSoftwareArchivePanel() {
		loadSoftwares();
	}

}
